﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ADRoot
{
    /// <summary>
    /// 只是完成程序的进入,不连接数据库.
    /// 连接数据库的功能放到主控界面,在需要的时候再连接数据库
    /// </summary>
    public partial class Login : Form
    {
        MainControler mainControler;
        public Login()
        {
            InitializeComponent();
            CenterToScreen();
            MaximizeBox = false;
            MinimizeBox = false;
            ShowInTaskbar = false;
        }
        /// <summary>
        /// exit
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        /// <summary>
        /// login
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {

            bool rtn = true;
            try
            {
                if (this.textBox_name.Text.Equals("root")
                    && textBox_password.Text.Trim().Equals(ConfigurationManagement.getConfigByKey("dbpassword")))
                {
                    rtn = true;
                }
                if (rtn)
                {
                    mainControler = new MainControler();
                    //这里把登陆窗口的Owner设置为mainControler,这样,当mainControler关掉的时候,登陆窗口也
                    //跟着关掉了
                    this.Owner = mainControler;
                    this.Hide();
                    mainControler.Show();
                }
                else
                {

                    MessageBox.Show("用户名密码不正确", "错误提示");
                }
            }
            catch
            {
                MessageBox.Show("程序异常", "提示");
            }
        }
    }
}
